package com.zhx.learn.component;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.zhx.learn.exception.ZhxAuth2Exception;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 *describe: 序列化 oauth2的错误
 *
 *@author zhanghaixuan
 *@date 2018/12/28
 **/
@Slf4j
public class ZhxAuth2ExceptionSerializer extends StdSerializer<ZhxAuth2Exception> {
	public ZhxAuth2ExceptionSerializer() {
		super(ZhxAuth2Exception.class);
	}

	@Override
	public void serialize(ZhxAuth2Exception value, JsonGenerator gen, SerializerProvider provider) throws IOException {
		gen.writeStartObject();
		log.error("ZhxAuth2ExceptionSerializer 验证错误:" + value.getOAuth2ErrorCode());
		gen.writeString(value.getMessage());
		gen.writeEndObject();
	}
}
